import type { UserAccountLoginParams } from '~/api/params/AccountLoginParams.ts'
import type { UserMobileLoginParams } from '~/api/params/MobileLoginParams.ts'
import type { UserLoginResult } from '~/api/vo/loginResult.ts'
import { usePost } from '@/utils/request.ts'
import type { UserInfo } from '@/api/model/user.ts'

/**
 * @ProjectName： naive-admin
 * @FileName： userApi
 * @Description: // 用户接口
 * @Author: ellwood
 * @date: 2024/1/18 - 8:23
 * @Version: V1.0.0
 */
// 登录接口
const userLoginUrl = '/user/login'
// 获取验证码接口
const userSendCodeUrl = '/user/send-code'
// 获取登录用户信息
const userGetInfoUrl = '/user/info'
// const userGetInfoUrl = '/test/401'

export type UserSendCodeParams = Pick<UserMobileLoginParams, 'mobile'>

// 登录实现
function userLoginApi(params: UserAccountLoginParams | UserMobileLoginParams) {
  return usePost<
        UserMobileLoginParams | UserAccountLoginParams,
        UserLoginResult
    >(userLoginUrl, params)
}

// 获取验证码
function userSendCodeApi(params: UserSendCodeParams) {
  return usePost<UserSendCodeParams, any>(userSendCodeUrl, params)
}

function userGetInfoApi() {
  return useGet<any, UserInfo>(userGetInfoUrl)
}

export {
  userLoginApi,
  userLoginUrl,
  userSendCodeUrl,
  userSendCodeApi,
  userGetInfoUrl,
  userGetInfoApi,
}
